﻿<UserControl x:Class="Apps.Yunwei.TopicViewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             xmlns:local="clr-namespace:Apps.Yunwei.ViewModels"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
    <UserControl.Resources>
        <Style TargetType="sdk:TreeViewItem" BasedOn="{StaticResource TreeViewItem}">
            <!--<Setter Property="IsExpanded" Value="{Binding IsExpanded,Mode=TwoWay}" />-->
        </Style>
        <sdk:HierarchicalDataTemplate x:Key="DataTemplate" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal">
                <Border HorizontalAlignment="Left" VerticalAlignment="Center"
                        Background="{Binding Background
                        ,FallbackValue={StaticResource TileBrush}
                        ,TargetNullValue={StaticResource TileBrush}}">
                    <Image Source="{Binding ImageUrl1}" Width="16" Height="16"/>
                </Border>
                <TextBlock Text="{Binding Caption}" Margin="2,2,0,2"/>
                <!--<TextBlock Text="{Binding Tags}" Margin="2,2,0,2"/>-->
            </StackPanel>
        </sdk:HierarchicalDataTemplate>
    </UserControl.Resources>
    <UserControl.DataContext>
        <local:TopicsViewModel/>
    </UserControl.DataContext>
    <Grid x:Name="LayoutRoot" Margin="5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="280" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.ColumnSpan="2" Margin="5" Grid.Row="0" Orientation="Horizontal">
            <StackPanel Orientation="Horizontal">
                <Button Content="新建应用" Width="75" Height="23" HorizontalAlignment="Left"
                        CommandParameter="{Binding SelectedItem, ElementName=treeView, Mode=OneWay}"
                        Command="{Binding AddAppCommand}" Cursor="Hand"/>

                <Button Content="新建服务" Width="75" Height="23" HorizontalAlignment="Left" Margin="8,0,0,0"
                        CommandParameter="{Binding SelectedItem, ElementName=treeView, Mode=OneWay}"
                        Command="{Binding AddSerCommand}" Cursor="Hand"/>

                <Button Content="删除" Width="75" Height="23" HorizontalAlignment="Left" Margin="8,0,0,0"
                        CommandParameter="{Binding SelectedItem, ElementName=treeView, Mode=OneWay}"
                        Command="{Binding DeleteCommand}" Cursor="Hand"/>

                <Button Content="保存" Width="75" Height="23" HorizontalAlignment="Left" Margin="8,0,0,0"
                        Command="{Binding SaveCommand}" Cursor="Hand"/>
                
                <!--<Button Content="展开" Width="75" Height="23" HorizontalAlignment="Left" Margin="8,0,0,0"
                        Command="{Binding ExpandedAll}" Cursor="Hand"/>-->

                <!--<Button Content="折叠" Width="75" Height="23" HorizontalAlignment="Left" Margin="8,0,0,0"
                        Command="{Binding CollpasedAll}" Cursor="Hand"/>-->
            </StackPanel>
        </StackPanel>
        <Grid Margin="5" Grid.Row="1">
            <sdk:TreeView x:Name="treeView" ItemsSource="{Binding Datas}" ItemTemplate="{StaticResource DataTemplate}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectedItemChanged" SourceName="treeView">
                        <i:InvokeCommandAction
                            Command="{Binding SelectedCommand}"
                            CommandParameter="{Binding SelectedItem, ElementName=treeView, Mode=OneWay}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </sdk:TreeView>
            <toolkit:BusyIndicator IsBusy="{Binding TreeIsBusy}" BusyContent="载入中...请稍等！"/>
        </Grid>
        <Grid Margin="5" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2">
            <Border Child="{Binding EditView}"/>
            <toolkit:BusyIndicator IsBusy="{Binding DetailIsBusy}" BusyContent="载入中...请稍等！"/>
        </Grid>
    </Grid>
</UserControl>